﻿using System.Collections.Generic;
using Hrm.Core;

namespace Hrm.EntityFramework.MigrationsPermission
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    /// <summary>
    /// Add-Migration -configuration Hrm.EntityFramework.MigrationsPermission.Configuration Initial
    /// Update-Database -configuration Hrm.EntityFramework.MigrationsPermission.Configuration -Verbose
    /// </summary>
    internal sealed class Configuration : DbMigrationsConfiguration<Hrm.EntityFramework.PermissionContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
            MigrationsDirectory = @"MigrationsPermission";
        }

        protected override void Seed(Hrm.EntityFramework.PermissionContext context)
        {
            //Application app = new Application() { Name = "管理平台" };
            //context.Applications.AddOrUpdate(p => p.Name, app);

            //var Resource1 = new Resource() { Type = "menu", Code = "Todo", Name = "代办", ParentCode = "root", GlyphiconsClass = "glyphicon glyphicon-home", Order = 1, Url = "/#/", Description = "´ý°ìÊÂÏî", Application = app };
            //var Resource2 = new Resource() { Type = "menu", Code = "Organization", Name = "组织机构", ParentCode = "root", GlyphiconsClass = "glyphicon glyphicon-user", Order = 2, Url = "#", Description = "×éÖ¯»ú¹¹", Application = app };
            //var Resource3 = new Resource() { Type = "menu", Code = "Companies", Name = "公司", ParentCode = "Organization", GlyphiconsClass = "glyphicon glyphicon-home", Order = 3, Url = "/Hrm/Companies/Index", Description = "¹«Ë¾¹ÜÀí", Application = app };
            //var Resource4 = new Resource() { Type = "menu", Code = "Departments", Name = "部门", ParentCode = "Organization", GlyphiconsClass = "glyphicon glyphicon-home", Order = 4, Url = "/Hrm/Departments/Index", Description = "²¿ÃÅ¹ÜÀí", Application = app };
            //var Resource5 = new Resource() { Type = "menu", Code = "Staffs", Name = "员工", ParentCode = "Organization", GlyphiconsClass = "glyphicon glyphicon-home", Order = 5, Url = "/Hrm/Staffs/Index", Description = "Ô±¹¤¹ÜÀí", Application = app };
            //var Resource6 = new Resource() { Type = "menu", Code = "Permission", Name = "权限", ParentCode = "root", GlyphiconsClass = "glyphicon glyphicon-lock", Order = 6, Url = "#", Description = "È¨ÏÞ¹ÜÀí", Application = app };
            //var Resource7 = new Resource() { Type = "menu", Code = "Applications", Name = "应用", ParentCode = "Permission", GlyphiconsClass = "glyphicon glyphicon-home", Order = 7, Url = "/Permissions/Applications/Index", Description = "Ó¦ÓÃ¹ÜÀí", Application = app };
            //var Resource8 = new Resource() { Type = "menu", Code = "Permissions", Name = "权限", ParentCode = "Permission", GlyphiconsClass = "glyphicon glyphicon-home", Order = 8, Url = "/Permissions/Permissions/Index", Description = "¹¦ÄÜ¹ÜÀí", Application = app };
            //var Resource9 = new Resource() { Type = "menu", Code = "Resources", Name = "资源", ParentCode = "Permission", GlyphiconsClass = "glyphicon glyphicon-home", Order = 9, Url = "/Permissions/Resources/Index", Description = "²Ëµ¥¹ÜÀí", Application = app };
            //var Resource10 = new Resource() { Type = "menu", Code = "Roles", Name = "角色", ParentCode = "Permission", GlyphiconsClass = "glyphicon glyphicon-home", Order = 10, Url = "/Permissions/Roles/Index", Description = "½ÇÉ«¹ÜÀí", Application = app };
            //var Resource11 = new Resource() { Type = "menu", Code = "Users", Name = "用户", ParentCode = "Permission", GlyphiconsClass = "glyphicon glyphicon-home", Order = 11, Url = "/Permissions/Users/Index", Description = "ÓÃ»§¹ÜÀí", Application = app };
            //var Resource12 = new Resource() { Type = "menu", Code = "ClassmateInfo", Name = "同学", ParentCode = "root", GlyphiconsClass = "glyphicon glyphicon-heart", Order = 12, Url = "#", Description = "Í¬Ñ§ÐÅÏ¢", Application = app };
            //var Resource13 = new Resource() { Type = "menu", Code = "Classmate", Name = "同学", ParentCode = "ClassmateInfo", GlyphiconsClass = "glyphicon glyphicon-home", Order = 13, Url = "/Hrm/ClassMates/Index", Description = "Í¬Ñ§¹ÜÀí", Application = app };
            //var Resource14 = new Resource() { Type = "menu", Code = "School", Name = "学校", ParentCode = "ClassmateInfo", GlyphiconsClass = "glyphicon glyphicon-home", Order = 14, Url = "/Hrm/Schools/Index", Description = "Ñ§Ð£¹ÜÀí", Application = app };
            //context.Resources.AddOrUpdate(p => p.Code, Resource1, Resource2, Resource3, Resource4, Resource5, Resource6, Resource7, Resource8, Resource9, Resource10, Resource11, Resource12, Resource13, Resource14);

            //var Permission1 = new Permission { Code = "Read", Name = "读" };
            //var Permission2 = new Permission { Code = "Write", Name = "写" };
            //context.Permissions.AddOrUpdate(p => p.Name,
            //    Permission1,
            //    Permission2
            //    );

            //User user = new User()
            //{
            //    Code = "david.zhang",
            //    Telephone = "1111111",
            //    Name = "张晓亮",
            //    Password = Hrm.Core.EncryptionTool.getMd5("111111"),
            //};
            //User user2 = new User()
            //{
            //    Code = "wei.tian",
            //    Telephone = "1111111",
            //    Name = "田位",
            //    Password = Hrm.Core.EncryptionTool.getMd5("111111"),
            //};
            //context.Users.AddOrUpdate(p => p.Name, user);
            //context.Users.AddOrUpdate(p => p.Name, user2);

            //var resourceAndPermission1 = new ResourceAndPermission() { Resource = Resource1, Permission = Permission1 };
            //var resourceAndPermission2 = new ResourceAndPermission() { Resource = Resource2, Permission = Permission2 };
            //var resourceAndPermission3 = new ResourceAndPermission() { Resource = Resource3, Permission = Permission2 };
            //var resourceAndPermission4 = new ResourceAndPermission() { Resource = Resource4, Permission = Permission2 };
            //var resourceAndPermission5 = new ResourceAndPermission() { Resource = Resource5, Permission = Permission2 };
            //context.ResourceAndPermissions.AddOrUpdate(p => p.Id,
            //    resourceAndPermission1,
            //    resourceAndPermission2,
            //    resourceAndPermission3,
            //    resourceAndPermission4,
            //    resourceAndPermission5);

            //var role1 = new Role { Code = "admin", Name = "管理员", Users = new List<User>() };
            //var role2 = new Role { Code = "guest", ResourceAndPermissions = new List<ResourceAndPermission>(), Name = "客人", Users = new List<User>() };//
            //role1.Users.Add(user);
            //role2.Users.Add(user2);
            //role2.ResourceAndPermissions.Add(resourceAndPermission1);
            //role2.ResourceAndPermissions.Add(resourceAndPermission2);
            //role2.ResourceAndPermissions.Add(resourceAndPermission3);
            //role2.ResourceAndPermissions.Add(resourceAndPermission4);
            //role2.ResourceAndPermissions.Add(resourceAndPermission5);
            //context.Roles.AddOrUpdate(p => p.Name,
            //    role1,
            //    role2);

            //var dictionary1 = new Dictionary() { Code = "menu", Name = "菜单", Type = "rourse" };
            //var dictionary2 = new Dictionary() { Code = "page", Name = "页面", Type = "rourse" };
            //var dictionary3 = new Dictionary() { Code = "json", Name = "数据", Type = "rourse" };
            //context.Dictionarys.AddOrUpdate(p => p.Name, dictionary1, dictionary2, dictionary3);
        }
    }
}
